﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZG_member;
using System.Net;
using System.Configuration;
using System.IO;
using ZG_member.DAL;




namespace ZG_member
{
    public partial class schedule : Form
    {
        string aa = "";
        public schedule(string a)
        {
            InitializeComponent();
            aa = a;
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
        }

        private void schedule_Load(object sender, EventArgs e)
        {
            this.timer2.Start();
            this.timer1.Start();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Stop();
            if (aa == "0")
            {
                this.Text = "数据上传...";
                SQLsynchronization sc = new SQLsynchronization(ConfigurationManager.AppSettings["bendi"]);
                List<string> tablename = sc.Gettablename();
                for (int i = 0; i < tablename.Count; i++)
                {
                    this.label2.Text = tablename[i];
                    this.progressBar1.Maximum = tablename.Count;
                    this.progressBar1.Value++;
                    Application.DoEvents();
                    sc.synchronization(tablename[i]);
                }
                sc.chazhi();

                string x = "1";
                StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
                sw.Flush();
                sw.Write(x);
                sw.Close();
                
                this.Close();
            }
            else if (aa == "1")
            {
                this.Text = "数据下载...";
                string xiazaisql = ConfigurationManager.AppSettings["bendi"];
                ConfigurationManager.AppSettings["ConnectionString"] = xiazaisql;

                SQLsynchronization sc = new SQLsynchronization(ConfigurationManager.AppSettings["fuwuqi"]);
                List<string> tablename = sc.Gettablename();
                for (int i = 0; i < tablename.Count; i++)
                {
                    this.label2.Text = tablename[i];
                    this.progressBar1.Maximum = tablename.Count;
                    this.progressBar1.Value++;
                    Application.DoEvents();
                    sc.synchronization(tablename[i]);
                    //if (tablename[i]=="memberInfo")
                    //{

                    //}
                }
                
                string xiazaisqlOK = ConfigurationManager.AppSettings["fuwuqi"];
                ConfigurationManager.AppSettings["ConnectionString"] = xiazaisqlOK;
                string x = "2";
                StreamWriter sw = new StreamWriter(Application.StartupPath + "\\Sqlupdate.txt", false, Encoding.GetEncoding("gb2312"));
                sw.Flush();
                sw.Write(x);
                sw.Close();
                this.Close();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer2.Stop();

            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer3.Stop();
                this.Close();
            }
        }
        int flag = 0;
        private void schedule_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer3.Start();
            }
        }
    }
}
